package com.yuliang.ai.controller;

import com.alibaba.fastjson.JSONArray;
import com.yuliang.ai.domain.Vo.KeywordsVo;
import com.yuliang.ai.global.Constants.RedisConf;
import com.yuliang.utils.result.ResultUtils;
import com.yuliang.utils.result.emums.HttpCodeEnum;
import com.yuliang.utils.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author Huangkai
 */
@Slf4j
@RestController
@RequestMapping("/ai")
public class SensitiveWordFilter {

    @PostMapping("/sensitiveWordFilter")
    public String SensitiveWordFilter(@RequestBody KeywordsVo keywordsVo) {
        String keywords = keywordsVo.getKeywords();
        List<String> keywordList = JSONArray.parseArray(RedisUtils.get(RedisConf.sensitiveWordListKey), String.class);
        for(String str :keywordList){
            if(keywords.indexOf(str) > 0){
                return ResultUtils.ResultWithMessageEnum(HttpCodeEnum.check_sensitive_word_fail);
            }
        }
        return ResultUtils.ResultWithMessageEnum(HttpCodeEnum.check_sensitive_word_success);
    }
}
